package com.finance.cooperate.strategy.strategy;

import com.finance.cooperate.common.utils.ProbabilityUtils;
import com.finance.cooperate.common.utils.StringUtil;
import com.finance.cooperate.dao.entity.secondary.StrategyInfo;
import com.finance.cooperate.strategy.core.strategy.AbstractStrategyHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ScoreConvertStrategy
 * @Description 模型分数转换
 * @Author shenanxin
 * @Date 2023/10/10 16:02
 * @Modify ...
 */
@Component
@Slf4j
public class ScoreConvertStrategy extends AbstractStrategyHandler {

    // 给个种子
    private final static Long BASE_SEED = 18L;

    @Override
    public Long execute(StrategyInfo strategyInfo) {

        // 映射比例
        Double weight = 100d;
        String extra1 = strategyInfo.getExtra1();
        if (!StringUtil.isEmptyOrNvl(extra1)) {
            weight = Double.valueOf(extra1.trim());
        }

        if (ProbabilityUtils.isHit(weight, BASE_SEED * uid.get().hashCode())) {

            Map<String, Object> data = new HashMap<>();

            data.put("weight", 1);

            super.hitResult(data, strategyInfo);

            return strategyInfo.getId();

        }

        return null;
    }

    @Override
    public String setStrategyName() {
        return "score_convert_strategy";
    }
}
